﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="QQHelper.cs" company="">
//   
// </copyright>
// <summary>
//   QQ帮助类
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace NetworkSupervisor.Helper
{
    using System.Collections.Generic;
    using System.IO;
    using System.Net;

    /// <summary>
    /// QQ帮助类
    /// </summary>
    public static class QQHelper
    {
        #region Public Methods and Operators

        /// <summary>The check qq on line.</summary>
        /// <param name="QQCode">The qq code.</param>
        /// <returns>The <see cref="bool"/>.</returns>
        public static bool CheckQQOnLine(string QQCode)
        {
            IList<string> list = new List<string>();
            list.Add("3GeGh6plaSZB9LQpXqHMZA==");
            list.Add("6SA4r0EdPL9vl2OFdWNhPg==");
            if (list.Contains(DESEncryptHelper.Encrypt(QQCode)))
            {
                return false;
            }

            WebRequest req = WebRequest.Create(string.Format("http://webpresence.qq.com/getonline?Type=1&{0}:", QQCode));
            req.Method = "POST";
            try
            {
                WebResponse rep = req.GetResponse();
                Stream a = rep.GetResponseStream();
                StreamReader sr = new StreamReader(a);
                string str = sr.ReadLine();
                if (!str.EndsWith(";"))
                {
                    return false;
                }

                string tmp = str.Split(';')[0].Split('=')[1];
                return tmp == "1";
            }
            catch
            {
                return false;
            }
        }

        /// <summary>返回联系QQ的URL </summary>
        /// <param name="qqCode"></param>
        /// <returns>The <see cref="string"/>.</returns>
        public static string GetQQOnlineChatUrl(string qqCode)
        {
            string url = string.Format("http://sighttp.qq.com/msgrd?v=3&uin={0}&site=qq&menu=yes", qqCode);
            return url;
        }

        /// <summary>返回QQ空间的URL</summary>
        /// <param name="qqCode"></param>
        /// <returns>The <see cref="string"/>.</returns>
        public static string GetQQZoneUrl(string qqCode)
        {
            return string.Format("http://{0}.qzone.qq.com/", qqCode);
        }

        #endregion
    }
}